package com.itic.mall.mobile.store;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.itic.appbase.framework.type.UserType;
import com.itic.mall.mobile.base.BaseMobileInterface;
import com.itic.mall.system.store.storeInfo.persistence.model.StoreInfo;
import com.itic.mall.system.store.storeInfo.service.StoreInfoService;
import com.itic.mall.system.users.usersmall.persistence.model.UsersMall;
@Controller
@RequestMapping(value="/mobile/store")
public class StoreInfoInterface extends BaseMobileInterface{
	@Autowired
	@Lazy
	private StoreInfoService storeInfoService;
	
	/**
	 * 店铺基本信息接口
	 * 
	 * */
	@RequestMapping(value="/info")
	@ResponseBody
	public Map<String, Object> info(HttpServletRequest request,HttpServletResponse response, String token, String appId ) {/*
		Map<String, Object> resultMap = new HashMap<String,Object>();
		//效验参数
		if(!StringUtils.isNoneBlank(appId,token)) {
			resultMap.put(CODE, PARAM_ERROR_CODE);
			resultMap.put(MSG, PARAM_ERROR_MSG);
			return resultMap;
		}
	    try {
	    	UsersMall usersMall = getUsersByTokenAndAppId(token,appId);
			//效验用户登录是否过期
		    if(usersMall == null) {
				resultMap.put(CODE, LOGIN_ERROR_CODE);
				resultMap.put(MSG, LOGIN_ERROR_MSG);
				return resultMap;
			}
		    StoreInfo info = this.storeInfoService.findInfoByUserIdAndYDZId(usersMall.getId(), usersMall.getYunId());
		    //判断是否是云店主 和是否开店
		    if(!UserType.isYDZ(usersMall.getType()) || info == null) {
		       	resultMap.put(CODE, Not_OPEDN_YDZ_ERROR_CODE);
				resultMap.put(MSG, Not_OPEDN_YDZ_ERROR_MSG);
				return resultMap;
		    }
		    JSONObject result = (JSONObject) JSONObject.toJSON(info);
		    result.put("balcance",usersMall.getMoney());
		    result.put("teamNum", info.getOneLevelCount()+info.getTwoLevelCount());
		    resultMap.put(CODE, SUCCESS_ERROR_CODE);
			resultMap.put(MSG, SUCCESS_ERROR_MSG);
			resultMap.put(DATA, result);
			isCrrossDomain(response);
			return resultMap;
		} catch (Exception e) {
	       	resultMap.put(CODE, SERVER_ERROR_CODE);
			resultMap.put(MSG, SERVER_ERROR_MSG);
			logException("StoreInfoInterface", "YDZInfo", e.toString(),"云店主店铺信息页面",e);
			return resultMap;
		}
		
	*/		return null;
	}
	
	
	

}
